package GUI;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import main.ScreenController;

import GUI.TabPanels.BookingPanel;
import GUI.TabPanels.CheckInPanel;
import GUI.TabPanels.CheckOutPanel;
import GUI.TabPanels.ViewBillPanel;
import GUI.TabPanels.ViewGuestsPanel;

@SuppressWarnings("serial")
public class EmployeeScreen extends JPanel{
	private JTabbedPane tabs;

	private BookingPanel booking_panel;
	private CheckInPanel check_in_panel;
	private CheckOutPanel check_out_panel;
	private ViewGuestsPanel view_guests_panel;
	private ViewBillPanel view_bills_panel;
	
	private JButton logout_button;
	
	private ScreenController sc;

	public EmployeeScreen(){
		this.setLayout(new BorderLayout());
		
		sc = ScreenController.getInstance();

		logout_button = new JButton("Logout");
		logout_button.addActionListener(new LogoutButton());
		
		this.add(logout_button, BorderLayout.EAST);
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//setTitle("Suite Dreams Employee Version");
		setSize(900,600);
		//setResizable(false);
		//this.setBackground(Color.PINK);


		tabs = new JTabbedPane();
		this.add(tabs, BorderLayout.SOUTH);
		tabs.addChangeListener(new TabChanged());

		booking_panel = BookingPanel.getInstance();
		check_in_panel = new CheckInPanel();
		check_out_panel = new CheckOutPanel();
		view_guests_panel = new ViewGuestsPanel();
		view_bills_panel = new ViewBillPanel();

		tabs.addTab("Booking", booking_panel);
		tabs.addTab("Check-In", check_in_panel);
		tabs.addTab("Check-Out", check_out_panel);
		tabs.addTab("Current Guests", view_guests_panel);
		tabs.addTab("View Bill", view_bills_panel);

		setVisible(true);
		tabs.repaint();
	}

	private class TabChanged implements ChangeListener{

		@Override
		public void stateChanged(ChangeEvent e) {
			check_in_panel.UpdateTable();
			check_out_panel.UpdateTable();
			view_guests_panel.UpdateTable();

			tabs.repaint();

			//			if(tabs.getSelectedComponent() == check_in_panel){
			//				check_in_panel.Update();
			//			}else if(tabs.getSelectedComponent() == check_out_panel){
			//				check_out_panel.Update();
			//			}else if(tabs.getSelectedComponent() == view_guests_panel){
			//				view_guests_panel.Update();
			//			}
			tabs.repaint();
		}

	}
	
	private class LogoutButton implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			sc.ViewLoginScreen();
		}
	}
}
